package pos.presentacion;

import java.io.IOException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;


public class FrontController3 extends HttpServlet {
	String noticia = "";
	String fecha = "";
	String etiqueta="";   
    /**
     * @see HttpServlet#HttpServlet()
     */
	public void init() throws ServletException {
	}

    protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		processRequest(request, response);

	}

	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		processRequest(request, response);
	}

	public void processRequest(HttpServletRequest request,
			HttpServletResponse response) throws IOException, ServletException {
		System.out.println("3");
	if(vacio(request)==false){
		String resource = request.getParameter("res");
		RequestDispatcher d = request.getRequestDispatcher(resource);
		if(d!=null){
			d.forward(request,response);
		}
	}else{
			response.sendRedirect("errorRegistro.jsp");
		}
	}
	public boolean vacio(HttpServletRequest request){
		boolean vacio=false;
		HttpSession session=request.getSession(false);
		String noticiaForm = request.getParameter("noticia");
		String fechaForm = request.getParameter("fecha");
		String etiquetaForm = request.getParameter("etiqueta");
		session = request.getSession();
			if (noticiaForm == null || fechaForm == null || etiquetaForm == null
					|| noticiaForm.length() == 0 || fechaForm.length() == 0
					|| etiquetaForm .length() == 0) {
				vacio = true;
				System.out.println("3");
			} else {
					vacio = false;
					System.out.println("3");
					session.setAttribute("session.noticia", noticiaForm);
					session.setAttribute("session.fecha", fechaForm);
					session.setAttribute("session.etiqueta", etiquetaForm);
			}
			return vacio;
	}

}
